package com.zyit.web;

import com.google.gson.Gson;
import com.zyit.DataObject.T_user;
import com.zyit.dao.UserDao;
import com.zyit.service.AdminService;
import com.zyit.service.Impl.AdminServiceImpl;
import com.zyit.util.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import java.sql.SQLException;
import java.util.List;

@WebServlet("/userList")
public class UserListServlet extends HttpServlet {
    private AdminService adminService = new AdminServiceImpl();

    UserDao bookDao  =new UserDao();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(66);
        String pageNo = req.getParameter("page");
        Integer currPage = 1;
        try {
            currPage = Integer.valueOf(pageNo);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        Page<T_user> pageInfo = null;
        try {
            pageInfo = bookDao.findByPage(currPage);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        String json = new Gson().toJson(pageInfo);
        System.out.println(json);

        resp.setContentType("application/json");


        resp.setCharacterEncoding("UTF-8");


        resp.getWriter().write(json);


    }

}